namespace SimpleWebServices.Web.Mvc
{
    using System;
    using System.Globalization;
    using System.Net;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    using SimpleWebServices.Configuration;
    using SimpleWebServices.Web;
    using SimpleWebServices.Web.Routing;

    [InternalServerError]
    public sealed class TenantMaintenanceController : TenantController, IRegisterRoutes
    {
        private static readonly CultureInfo English = new CultureInfo("en");

        void IRegisterRoutes.Register(RouteCollection routes)
        {
            if (null == routes)
            {
                throw new ArgumentNullException("routes");
            }

            routes.MapRoute(
                "{*url}",
                "{*url}",
                new { controller = "TenantMaintenance", action = "HtmlRepresentation" });
        }

        public ActionResult HtmlRepresentation()
        {
            HttpResponseBase response = HttpContextFactory.Current.Response;
            response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
            response.Cache.SetCacheability(HttpCacheability.NoCache);

            return this.HtmlView(English, new Default().Object<Maintenance>().ApplyDefaultValues<Maintenance>());
        }
    }
}